package cn.edu.ctbu.controller.user;

import cn.edu.ctbu.DTO.ShoppingCartDTO;
import cn.edu.ctbu.entity.ShoppingCart;
import cn.edu.ctbu.result.Result;
import cn.edu.ctbu.service.IShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/cart")
public class CartController {
    @Autowired
    IShoppingCartService iShoppingCartService;

    /**
     * 修改购物车列表
     */
    @PostMapping
    @ApiOperation("添加购物车")
    public Result put(@RequestBody List<ShoppingCartDTO> dto){
        iShoppingCartService.put(dto);
        return  Result.success();
    }

    /**
     * 获得购物车
     */
    @GetMapping
    @ApiOperation("获得购物车列表")
    public Result<List<ShoppingCart>> get(){
        List<ShoppingCart> cart=iShoppingCartService.get();
        return Result.success(cart);
    }
}
